package Work02;

import java.util.List;

public class Order {
    private String orderId;
    private String userId;
    private double totalAmount;
    private List<OrderItem> items;

    public Order() {
    }

    public Order(String orderId, String userId, List<OrderItem> orderItemList) {
        this.orderId = orderId;
        this.userId = userId;
        this.items = orderItemList;
        setTotalAmount();
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }
    public void setTotalAmount() {
        double sum=0;
        for (OrderItem orderItem : items) {
            sum+=orderItem.getPrice()*orderItem.getQuantity();
        }
        this.totalAmount=sum;
    }
    public double getTotalAmount() {
        return totalAmount;
    }



    public List<OrderItem> getItems() {
        return items;
    }

    public void setItems(List<OrderItem> orderItemList) {
        this.items = orderItemList;
    }

    @Override
    public String toString() {
        return "Order{" +
                "orderId='" + orderId + '\'' +
                ", userId='" + userId + '\'' +
                ", totalAmount=" + totalAmount +
                ", orderItemList=" + items +
                '}';
    }
}
